﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Babel.ParserGenerator;

namespace dragonangel.phpProject.Language.DSL
{
    public class CodeFile : CodeExpression
    {
        protected IList<CodeExpression> expressions = new List<CodeExpression>();

        public IList<CodeExpression> Expressions
        {
            get { return expressions; }
            set { expressions = value; }
        }

        public override CodeExpression GetExpression(int line, int col)
        {
            foreach (CodeExpression exp in expressions)
            {
                CodeExpression result = exp.GetExpression(line, col);
                if (result != null)
                    return result;
            }
            return base.GetExpression(line, col);
        }

        public override CodeExpression GetFirstParentContainingMember(int line, int col)
        {
            foreach (CodeExpression exp in expressions)
            {
                CodeExpression result = exp.GetFirstParentContainingMember(line, col);
                if (result != null)
                    return result;
            }
            return base.GetFirstParentContainingMember(line, col);
        }

        public override LexLocation Begin
        {
            get
            {
                if (expressions.Count > 0)
                    return expressions[0].Begin;
                return new LexLocation();
            }
            set
            {
                throw new NotSupportedException();
            }
        }

        public override LexLocation End
        {
            get
            {
                if (expressions.Count > 0)
                    return expressions[expressions.Count - 1].End;
                return new LexLocation();
            }
            set
            {
                throw new NotSupportedException();
            }
        }
    }
}
